//author:kakake
var Model = /** @class */ (function () {
    function Model() {
        this.Books = {
            "model": {
                "Id": "",
                "BookName": "",
                "BuyPrice": "",
                "BuyDate": "yyyy-MM-dd",
                "language": "0",
                "memo": "",
                "Flag": "",
                "WorkId": 0
            },
            "tablename": "Books",
            "key": "Id",
            "val": "0",
            "objval": { "Id": 0, "BookName": "" },
            "query": {
                "BookName": "like"
            },
            "where": "",
            "pageinfo": {},
            "WorkId": 1
        };
    }
    return Model;
}());

//author:kakake
var Common = /** @class */ (function () {
    function Common() {
    }
    return Common;
}());

//author:kakake
var DoctorManageService = /** @class */ (function () {
    function DoctorManageService() {
    }
    return DoctorManageService;
}());

//author:kakake
var DoctorManageDao = /** @class */ (function () {
    function DoctorManageDao() {
        this.dbConn = TSLobsterAPI.Program.GetDbConn();
    }
    return DoctorManageDao;
}());

//author:kakake
var DoctorManageController = /** @class */ (function () {
    function DoctorManageController() {
        this.data = {
            dbConn: TSLobsterAPI.Program.GetDbConn()
        };
        this.TableModel = new Model().Books;
    }
    DoctorManageController.prototype.getdata = function () {
        var pageInfo = {
            key: "Id",
            page: TSLobsterAPI.Program.RequestQuery("page", "1"),
            perPage: TSLobsterAPI.Program.RequestQuery("limit", "10"),
            totalRecord: 100
        };
        this.TableModel.where = TSLobsterAPI.DbHelper.GetWhere(this.TableModel.query);
        this.TableModel.pageinfo = pageInfo;
        TSLobsterAPI.Utils.TrackLog("where", this.TableModel.where);
        TSLobsterAPI.Utils.TrackLog("WorkId", this.TableModel.WorkId);
        var datagrid = { data: {}, count: 0 };
        datagrid.data = TSLobsterAPI.DbHelper.GetListModelPage(this.data.dbConn, this.TableModel);
        datagrid.count = pageInfo.totalRecord;
        return datagrid;
    };
    DoctorManageController.prototype.savemodel = function () {
        var self = this;
        self.TableModel.objval = JSON.parse(TSLobsterAPI.Program.RequestBody());
        if (self.existbookname(self.TableModel.objval.BookName) && self.TableModel.objval.Id == 0) {
            throw '请不要添加重复的书籍名称';
        }
        TSLobsterAPI.Utils.TrackLog("TableModel", self.TableModel);
        TSLobsterAPI.DbHelper.SaveModel(self.data.dbConn, self.TableModel);
        return { result: true };
    };
    DoctorManageController.prototype.deletemodel = function () {
        var self = this;
        self.TableModel.val = TSLobsterAPI.Program.RequestQuery("Id", "0");
        TSLobsterAPI.DbHelper.DeleteModel(self.data.dbConn, self.TableModel);
        return { result: true };
    };
    DoctorManageController.prototype.existbookname = function (bookname) {
        var self = this;
        var strsql = "select count(1) ct from Books where bookname=?";
        var dbparams = [];
        dbparams.push(bookname);
        var res = TSLobsterAPI.DbHelper.DbGetJsonObject(self.data.dbConn, strsql, dbparams);
        if (res.ct > 0) {
            return true;
        }
        else {
            return false;
        }
    };
    return DoctorManageController;
}());

